import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import constant.Info;

import static constant.Info.BUCKET_NAME;
import static constant.Info.SECRET_KEY;


public class QiniuUploadDemo {

    public static void main(String[] args) {
        // 创建认证对象
        Auth auth = Auth.create(Info.ACCESS_KEY, SECRET_KEY);
        
        // 创建配置对象，指定区域，这里以华东为例
        Configuration cfg = new Configuration(Region.region1());
        
        // 创建上传管理器对象
        UploadManager uploadManager = new UploadManager(cfg);
        
        // 要上传的文件路径
        String localFilePath = "C:\\Users\\wy\\Desktop\\广州0320\\白云山肥鱼1.jpg";
        
        // 文件上传后的名称
        String key = "fish.jpg";
        
        try {
            // 获取上传凭证
            String upToken = auth.uploadToken(BUCKET_NAME);
            
            // 执行上传操作
            com.qiniu.http.Response response = uploadManager.put(localFilePath, key, upToken);
            
            // 解析响应结果
            System.out.println(response.bodyString());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}